class Solution(object):
    def countSubarrays(self, nums, minK, maxK):
        if minK > maxK:
            return 0
        n = len(nums)
        st = []
        left_min = [0] * n
        right_min = [0] * n
        for i in range(n):
            while st and nums[i] <= nums[st[-1]]:
                st.pop()
            if st:
                left_min[i] = i - 1 - st[-1]
            else:
                left_min[i] = 0
            st.append(i)
        st = []
        for i in range(n - 1, -1, -1):
            while st and nums[i] < nums[st[-1]]:
                st.pop()
            if st:
                right_min[i] = st[-1] - 1 - i
            else:
                right_min[i] = n - 1 - i
            st.append(i)
        print(left_min, right_min)


data = Solution()
nums = [1, 3, 5, 2, 7, 5]
minK = 1
maxK = 5
print(data.countSubarrays(nums, minK, maxK))
